<template>
	<view class="login">
		<image class="logo" :src="domain+'/uploads/default/wx_share_cover.jpg'"></image>
		<text class="txt1">申请获取以下权限</text>
		<text class="txt2">获取你的公开信息（昵称、头像等）</text>
		<u-button type="success" open-type="getUserInfo" @getuserinfo="userLogin" shape="circle">授权登录</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				domain: this.$H.domain
			};
		},
		onLoad() {

		},
		onShow() {

		},
		methods: {
			userLogin(e) {
				let that = this;
				// 获取用户信息
				uni.getUserInfo({
					lang: 'zh_CN',
					success: function(infoRes) {
						let userInfo = infoRes.userInfo;
						uni.login({
							success: function(res) {
								if (res.code) {
									that.$H.post('/api/member/wxLogin', {
										code: res.code,
										username: userInfo.nickName,
										avatar: userInfo.avatarUrl,
										province: userInfo.province,
										city: userInfo.city,
										gender: userInfo.gender
									}).then(res2 => {
										if (res2[1].data.code === 1) {
											uni.setStorageSync("hasLogin", true);
											uni.setStorageSync("sessionKey", res2[1].data.sessionKey);									
											uni.navigateBack();
										}
									})
								}
							}
						});
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	@import 'login.css';
</style>